# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=tzdata
pkgname=haskell-tzdata
pkgver=0.2.20230322.0
pkgrel=2
pkgdesc="Haskell package that distributes the standard time zone database"
url="https://github.com/ysangkok/haskell-tzdata"
license=('Apache')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-vector')
makedepends=('ghc' 'haskell-hunit' 'haskell-tasty' 'haskell-tasty-hunit' 'haskell-tasty-th')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('30b4de1bf84ad10ccaf71e6b5a296ff03a83478ba3110389a5f4c15770a77d13d2a2b09f22d71d8bac033418a995bb115f4dc2af2d3baccf32d29c36b71b2257')

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    # https://github.com/ysangkok/haskell-tzdata/issues/3
    runhaskell Setup test --show-details=direct || echo "Tests failed"
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
